﻿using DevExpress.XtraReports.UI;
using DevTeam;
using System;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.Rapor.Aksesuar
{
    public partial class xrAksesuarFoyu : DevExpress.XtraReports.UI.XtraReport
    {
        public xrAksesuarFoyu()
        {
            InitializeComponent();
        }

        public xrAksesuarFoyu(string idx, int BrandId)
            : this()
        {
            DataSet ds = Session.DataManager.ExecuteDataSet("GetAksesuarFoy", idx, BrandId);

            DataRow drHeader = ds.Tables[1].Rows[0];
            tcDosyaNo.Text = drHeader["DosyaNo"].ToString();
            tcDosyaNo2.Text = drHeader["DosyaNo"].ToString();
            tcTarih.Text = DateTime.Now.ToShortDateString();

            this.DataMember = "Table";
            this.DataSource = ds;

            pbPicture.DataBindings.Add("Image", null, "Photo2");
            tcKod.DataBindings.Add("Text", null, "Table.StokKod");
            tcKategori.DataBindings.Add("Text", null, "Table.Kategori");
            tcAciklama.DataBindings.Add("Text", null, "Table.Aciklama");
            tcQty.DataBindings.Add("Text", null, "Table.Qty");
        }

        private void tcAciklama_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            //ReSize(sender, 8, FontStyle.Regular);
        }

        private void tcKod_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            //ReSize(sender, 10, FontStyle.Bold);
        }

        private void ReSize(object sender, float newSize, FontStyle fontstyle)
        {
            //Resize ı düzgün yapan tek fonksiyon !!!
            Graphics gr = Graphics.FromHwnd(IntPtr.Zero);
            gr.PageUnit = GraphicsUnit.Millimeter;
            int factor = 10;

            XRLabel label = (XRLabel)sender;

            //float newSize = 8f;
            Font defaultFont = new System.Drawing.Font("Calibri", newSize, fontstyle);

            float stringWidth = gr.MeasureString(label.Text, defaultFont).Width;
            float labelWidth = label.WidthF;


            if (labelWidth < stringWidth * factor)
                newSize = defaultFont.Size * label.WidthF / stringWidth / factor;


            label.Font = new Font(defaultFont.FontFamily, newSize, fontstyle);
            gr.Dispose();
        }
    }
}
